<template>
  <view class="doctor">
    <view class="user-info">
      <view class="role" v-if="roleName&&roleIds.indexOf(',')>-1" @click="$util.goUrl('/pages/selectRole/index')"
        >{{ roleName }}<text class="iconfont icon-right"
      /></view>
      <view class="avatar" @click="$emit('showActionSheet', data.avatar)" v-if="data.name">
        <image v-if="data.avatar" :src="data.avatar" />
        <image v-else-if="data.sex < 0 || data.sex == 1" src="@/static/image/man.png" />
        <image v-else src="@/static/image/woman.png" />
      </view>
      <text
        v-if="data.sex > -1"
        :class="['iconfont', data.sex ? 'icon-nan' : 'icon-nv', 'gender']"
        :style="{ background: data.sex ? '#1DA1F3' : '#F86098' }"
      />
      <view class="msg">
        <view class="msg-item">
          <text class="name">{{ data.name || "" }}</text></view
        >
        <view class="msg-item">
          <text>{{ data.postName || "" }}</text
          >{{ data.departmentName || "" }}</view
        >
        <view class="msg-item"> {{ data.sysName||data.hospitalName || "" }}</view>
      </view>
    </view>
    <view class="statistics">
      <view class="statistics-item" @click="goMyPatient(3)">
        <text style="color: #e83112">{{ data.abnormalNum || 0 }}</text
        ><br />
        今日异常
      </view>
      <view class="statistics-item" @click="goMyPatient(4)">
        <text style="color: #e6a23c">{{ data.potentialLossNum || 0 }}</text
        ><br />
        潜在流失
      </view>
      <view class="statistics-item"  @click="goMyPatient(0)">
        <text>{{ data.patientNum || 0 }}</text
        ><br />
        患者数
      </view>
      <view class="statistics-item"  @click="goMyPatient(1)">
        <text>{{ data.hasTestNum || 0 }}</text
        ><br />
        已测量
      </view>
      <view class="statistics-item"  @click="goMyPatient(2)">
        <text style="color: #e83112">{{ data.notTestNum || 0 }}</text
        ><br />
        未测量
      </view>
      <view class="statistics-item" @click="$util.goUrl('/pagesDoctor/evaluate/index')">
        <text class="my-active" style="font-weight:bold">{{ evaluate.totalAvgScore || 0 }}</text
        ><br />
        患者评分
      </view>
    </view>
    <view style="background: #fff">
      <basics-list ref="basicsList" @listClick="listClick" />
    </view>
  </view>
</template>

<script>
import basicsList from "@/components/basics-list/basics-list.vue";

export default {
  components: { basicsList },
  props: {
    roleName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
	  roleIds:uni.getStorageSync("roleIds"),
      data: {},
      evaluate: {},
      urls: ["/pagesDoctor/myPatient/index", "/pagesDoctor/record/index", "/pagesPatient/message/index"],
    };
  },
  onShareAppMessage() {
    return this.$util.returnShareObj();
  },
  created() {
    this.$nextTick(() => {
      this.initBasicsList();
    });
  },
  methods: {
    //初始化
    init() {
          this.$util.requestLodingType = false;
      this.$api.doctorGetHomeInfo().then((res) => {
        if (res.code == 200) {
          this.data = res.data;
          this.initBasicsList();
          this.doctorCuntEvaluate()
          uni.setStorage({
            key: "doctorId",
            data: res.data.doctorId,
          });
        }
      });
      
    },
    //患者评价
    doctorCuntEvaluate(){
          this.$util.requestLodingType = false;
		this.$api.doctorCuntEvaluate({doctorId:this.data.doctorId}).then((res) => {
        if (res.code == 200) {
         this.evaluate=res.data
         uni.setStorage({
            key: "evaluate",
            data: res.data,
          });
        }
      });
    },
    //初始化列表
    initBasicsList() {
      let list = [
        { title: "我的患者", icon: "huanzheguanli", rightArrow: true },
        { title: "个人档案", icon: "gerendangan", rightArrow: true },
        { title: "系统消息", icon: "tuisongxiaoxi",placeholder:this.data&&this.data.notReadSysMsgNum?this.data.notReadSysMsgNum+'条未读':'',  rightArrow: true },
        { title: "查看设备", icon: "scan", rightArrow: true },
      ];
      this.$refs.basicsList.initList(list);
    },
    listClick(index) {
      if (index == 3) {
        this.scan();
      } else {
        this.$util.goUrl(this.urls[index]);
      }
    },
    goMyPatient(type){
        this.$util.goUrl("/pagesDoctor/myPatient/index?type="+type)
    },
    scan(clearItem) {
      if (clearItem) {
        this.item = null;
      }
      uni.scanCode({
        success: (res) => {
          if (res.errMsg == "scanCode:ok") {
            let index = res.result.indexOf("imei=");
            if (index < 0) {
			  this.getDetails(res.result, true);
            } else {
              this.getDetails(res.result.substring(index + 5, res.result.length), true);
            }
          } else {
            this.$util.showToast("无法识别该二维码");
          }
        },
      });
    },
    getDetails(deviceNo) {
      this.$api.doctorGetDeviceDetailByScanCode({ deviceNo }).then((res) => {
        if (res.code == 200) {
          uni.showModal({
            title: "设备详情",
            content: `设备编号：${res.data.deviceNo}\n 设备名称：${res.data.typeName}\n生产厂家：${res.data.factory}\n出厂日期：${res.data.dateOfProduction}`,
            showCancel: false,
          });
        }
      });
    },
    setAvatar(avatar) {
      this.data.avatar = avatar;
    },
  },
};
</script>
<style lang="scss" scoped>
.doctor {
	height: calc(100vh - 4rpx);
  .user-info {
    background: $theme-color;
    display: flex;
    padding: 0 40rpx 40rpx 40rpx;
    align-items: center;
    position: relative;
    min-height:218rpx;
    .role {
      position: absolute;
      right: 20rpx;
      bottom: 10rpx;
      z-index: 1000;
      font-size: $small-font-size;
      color: #fff;
    }
    .avatar {
      width: 160rpx;
      height: 160rpx;
      margin-right: 20rpx;
      border-radius: 140rpx;
      overflow: hidden;
      margin-top: 6rpx;
      box-shadow: rgba(14, 14, 14, 0.5) 0px 6rpx 15rpx 0px;
      border: 1rpx solid rgba(255, 255, 255, 0.7);
      padding: 4rpx;
      image {
        width: 100%;
        height: 100%;
        border-radius: 100%;
      }
    }
    .gender {
      z-index: 100;
      font-size: 30rpx;
      margin: 100rpx 0 0 -60rpx;
      z-index: 100;
      background: blue;
      color: #fff;
      height: 40rpx;
      line-height: 40rpx;
      text-align: center;
      width: 40rpx;
      border-radius: 40rpx;
      border: 4rpx solid rgba(255, 255, 255, 0.8);
    }
    .msg {
      color: #fff;
      width: calc(100% - 200rpx);
      margin-left: 40rpx;
      line-height: 40rpx;
      padding-top: 10rpx;
      &-item {
        margin-bottom: 10rpx;
        text:first-child {
          margin-right: 40rpx;
        }
        .name {
          font-weight: bold;
          font-size: $big-font-size;
        }
      }
    }
  }
  .statistics {
    display: flex;
    margin-bottom: 20rpx;
    border-bottom: 2rpx solid $default-border-color;
    background: #ffffff;
    flex-wrap: wrap;
    padding-bottom: 20rpx;
    position: relative;
    &-item {
      margin-top: 20rpx;
      width: 33.33vw;
      text-align: center;
      font-size: $litte-font-size;
      color: $font-grey-color;
      text {
        color: $default-color;
        font-size: $big-font-size;
      }
    }
  }
}
</style>
